#include<stdio.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<unistd.h>
#include<pthread.h>
#include <stdlib.h>

//function 
void *thread_run1(void* arg)
{
  printf("thread 1 returning ...\n");
  printf("%s, %lu, pid:%d, ppid: %d\n",(char*)arg, pthread_self(), getpid(), getppid());
  int *p = (int*)malloc(sizeof(int));
  *p = 1;
  //sleep(5);
  return (void*)10;
}

void *thread_run2(void* arg)
{
  printf("thread 2 returning ...\n");
  printf("%s, %lu, pid:%d, ppid: %d\n",(char*)arg, pthread_self(), getpid(), getppid());
  int *p = (int*)malloc(sizeof(int));
  *p = 2;
  //sleep(5);
  pthread_exit((void*)p);
}

void *thread_run3(void* arg)
{
  while(1){
    printf("thread 3 returning ...\n");
    sleep(1);
  }
  //sleep(5);
  return NULL;
}

int main()
{
  pthread_t tid;
  pthread_create(&tid, NULL, thread_run, "thread 1");

  printf("main :%lu, pid %d, ppid: %d\n",pthread_self(),getpid(), getppid());

  void* ret = NULL;
  pthread_join(tid,&ret);
  printf("thread quit code : %d \n",(long long)ret);
  return 20;
}
